﻿namespace Sidvall.WorkItemManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class IdentityProvider : global::Sidvall.WorkItemManager.UI.Entities.Core.BusinessBase, global::Sidvall.WorkItemManager.Data.IIdentityProvider
    {
        #region Business Members

        #region IdentityProviderId

        private System.Nullable<int> _IdentityProviderId = null;
        partial void OnBeforeIdentityProviderIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData);
        partial void OnBeforeIdentityProviderIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterIdentityProviderIdPropertyChanged();
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public System.Nullable<int> IdentityProviderId
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<int>>(_IdentityProviderId);
                OnBeforeIdentityProviderIdPropertyGet(eventData);
                return eventData.Value;
            }
            internal set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _IdentityProviderId);
                OnBeforeIdentityProviderIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("IdentityProviderId", eventData.Value, true, true, true);
                    OnAfterIdentityProviderIdPropertyChanged();
                }
            }
        }

        #endregion
        #region Password

        private string _Password = string.Empty;
        partial void OnBeforePasswordPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforePasswordPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterPasswordPropertyChanged();
        public string Password
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Password);
                OnBeforePasswordPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Password);
                OnBeforePasswordPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Password", eventData.Value, true, true, true);
                    OnAfterPasswordPropertyChanged();
                }
            }
        }

        #endregion
        #region STSAddress

        private string _STSAddress = string.Empty;
        partial void OnBeforeSTSAddressPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeSTSAddressPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSTSAddressPropertyChanged();
        public string STSAddress
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_STSAddress);
                OnBeforeSTSAddressPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _STSAddress);
                OnBeforeSTSAddressPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("STSAddress", eventData.Value, true, true, true);
                    OnAfterSTSAddressPropertyChanged();
                }
            }
        }

        #endregion
        #region STSClientId

        private string _STSClientId = string.Empty;
        partial void OnBeforeSTSClientIdPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeSTSClientIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSTSClientIdPropertyChanged();
        public string STSClientId
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_STSClientId);
                OnBeforeSTSClientIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _STSClientId);
                OnBeforeSTSClientIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("STSClientId", eventData.Value, true, true, true);
                    OnAfterSTSClientIdPropertyChanged();
                }
            }
        }

        #endregion
        #region STSClientSecret

        private string _STSClientSecret = string.Empty;
        partial void OnBeforeSTSClientSecretPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeSTSClientSecretPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterSTSClientSecretPropertyChanged();
        public string STSClientSecret
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_STSClientSecret);
                OnBeforeSTSClientSecretPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _STSClientSecret);
                OnBeforeSTSClientSecretPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("STSClientSecret", eventData.Value, true, true, true);
                    OnAfterSTSClientSecretPropertyChanged();
                }
            }
        }

        #endregion
        #region UserName

        private string _UserName = string.Empty;
        partial void OnBeforeUserNamePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeUserNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterUserNamePropertyChanged();
        public string UserName
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_UserName);
                OnBeforeUserNamePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _UserName);
                OnBeforeUserNamePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("UserName", eventData.Value, true, true, true);
                    OnAfterUserNamePropertyChanged();
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.IdentityProviderManager.GetKey(this);
            }
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.IdentityProviderManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.IdentityProviderManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public IdentityProvider Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public IdentityProvider Copy()
        {
            return Copy(null);
        }
        public IdentityProvider Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new IdentityProvider();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IIdentityProvider item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IIdentityProvider item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(IdentityProvider destination, global::Sidvall.WorkItemManager.Data.IIdentityProvider source, Sidvall.Data.CopySettings copySettings);
        private void Import(IdentityProvider destination, global::Sidvall.WorkItemManager.Data.IIdentityProvider source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.IdentityProviderManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(IdentityProvider destination, IdentityProvider source, Sidvall.Data.CopySettings copySettings);
        private void Import(IdentityProvider destination, IdentityProvider source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.WorkItemManager.Data.IIdentityProvider, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.IdentityProviderManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.IdentityProviderManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.IdentityProviderManager.Initialize(this, settings);
        }

        #endregion
        
        #region IIdentityProvider Members

        System.Nullable<int> global::Sidvall.WorkItemManager.Data.IIdentityProvider.IdentityProviderId
        {
            get
            {
                return this._IdentityProviderId;
            }
            set
            {
                this._IdentityProviderId = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IIdentityProvider.Password
        {
            get
            {
                return this._Password;
            }
            set
            {
                this._Password = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IIdentityProvider.STSAddress
        {
            get
            {
                return this._STSAddress;
            }
            set
            {
                this._STSAddress = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IIdentityProvider.STSClientId
        {
            get
            {
                return this._STSClientId;
            }
            set
            {
                this._STSClientId = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IIdentityProvider.STSClientSecret
        {
            get
            {
                return this._STSClientSecret;
            }
            set
            {
                this._STSClientSecret = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IIdentityProvider.UserName
        {
            get
            {
                return this._UserName;
            }
            set
            {
                this._UserName = value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public IdentityProvider()
        {
        }

        public IdentityProvider(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}